import { combineReducers } from 'redux'
import { ADD_TODO,TOGGLE_TODO,SET_VISIBILITY_FILTER,VisibilityFilters} from '../actions/Zscc'

function visibilityFilter(state=SHOW_ALL,action){
	switch(action.type){
		case SET_VISIBILITY_FILTER:
		  return action.filter
		default:
		  return state;
	}
}
function todos(state=[],action){
	switch (aciton.type){
		case ADD_TODO:
			return [
				...state,{
					text:action.text,
					completed:false
				}
			]
		case TOGGLE_TODO:
			return state.map((todo,index)=>{
				if(index===action.index){
					return Object.assign({},todo,{
						completed:!todo.completed
					})
				}
			})
		default:
			return state
	}
}

const todoApp=combineReducers({
	visibilityFilter,
	todos
})

export default todoApp